import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'

import './getCoupons.css'
import app from '../../main';

export default class GetCoupons extends Component {

    config = {
        navigationBarTitleText: '领取优惠券'
    }
    constructor(){
        super(...arguments)
        this.state = {
            coupons:[],//优惠券
        }
    }

    length = 20
    offset = 0
    total = 0

    //获取优惠券数据
    getData(){
        let me = this
        // console.log(1111)
        let data = {
            offset:this.offset,
            length:this.length
        }
        app.post('web/coupon/getCouponsList',data,function(res){
            console.log(res)
            me.total = res.data.result.total
            me.setState({
                coupons:res.data.result.result
            },()=>{
                console.log(me.state.coupons)
            })
        })
    }

    //上拉加载
    onReachBottom() {
        if(this.offect + this.length < this.total){
            app.toast("正在加载...")
            this.offect = this.offect + this.length
            this.getData()
        }else{
            app.toast("没有耕读数据了")
        }
    }

    componentWillMount () {
        this.getData()
        console.log(1111)
    }

    render () {
        return (
        <View className='image-text'>
           1111111111111111111 111
        </View>   
        )
    }
}     